package com.gtq.uhome.controller;

import com.gtq.uhome.result.Result;
import com.gtq.uhome.service.DeliveryPortOrderService;
import com.gtq.uhome.vo.OrderBasicInformation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ylhy
 * @Describe 配送端口订单列表的相关操作 de:  pick_time派送员取货时间
 * @Describe 配送端口订单列表的相关操作 de:  sign_code签收状态
 * @Describe 配送端口订单列表的相关操作 de:  status_code订单是否删除(0/1)
 * @Describe 配送端口订单列表的相关操作 de:  status_code订单是否删除(0/1)
 * @create 2020-08-08 15:33
 */
@Controller
@RequestMapping("/DeliveryPort")
@Api(value = "用于配送端口订单列表(非详情)接口-->饶平",tags = "配送端口-->订单列表(非详情)的api-->饶平")
@ResponseBody
@CrossOrigin
public class
DeliveryPortOrderController {

    private Integer lines;

    @Resource(name = "deliveryPortOrderService")
    DeliveryPortOrderService deliveryPortOrderService;

    @PostMapping("/pickUpOrderList")
    @ApiOperation(value = "查询待订单列表---待取货",notes = "前端必须传员工的id",httpMethod =
            "POST")
    public Result pickUpOrderList(@RequestBody Map map){

        Integer staffId = (Integer) map.get("staffId");
        List<OrderBasicInformation> pickUpOrderList;

        try {
            pickUpOrderList = deliveryPortOrderService.pickUpOrderList(staffId);
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        if (pickUpOrderList == null){
            return Result.failed("相关没查到订单");
        }
        return Result.ok(pickUpOrderList);
    }


    @PostMapping("/confirmReceipt")
    @ApiOperation(value = "确认取货",notes = "前端需要传递订单编号,收货人id,收货人姓名",httpMethod =
            "POST")
    public Result confirmReceipt(@RequestBody Map map){
        String orderId = (String) map.get("orderId");
        Integer userId = (Integer) map.get("userId");
        String consigneeName = (String) map.get("consigneeName");
        Integer lines;
        try {
            lines = deliveryPortOrderService.confirmReceipt(orderId,userId,consigneeName);
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        return Result.ok(lines);
    }


    @PostMapping("/waitSendOrderList")
    @ApiOperation(value = "查询待送货订单列表---待送货",notes = "前端必须传员工的id",httpMethod =
            "POST")
    public Result waitSendOrderList(@RequestBody Map map){

        Integer staffId = (Integer) map.get("staffId");

        List<OrderBasicInformation> waitSendOrderList;

        waitSendOrderList = deliveryPortOrderService.waitSendOrderList(staffId);
        System.out.println("waitSendOrderList:"+waitSendOrderList);

        try {
        }catch (Exception e){

            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        if (waitSendOrderList == null){

            return Result.failed("网络延迟,请稍等,数据已经保存");
        }else {

            return Result.ok(waitSendOrderList);
        }

    }




    @PostMapping("/confirmSign")
    @ApiOperation(value = "确认签收",notes = "前端必须传订单的 id : orderId,  签收情况 : signStatus,  详情 : signIn,用户id,收货人姓名",
            httpMethod =
            "POST")
    public Result confirmSign(@RequestBody Map<String,Object> map){
        System.out.println(map);
        try {
            lines = deliveryPortOrderService.confirmSign(map);
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        System.out.println(lines+"lines");
        return Result.ok(lines);
    }


    @PostMapping("/okOrderList")
    @ApiOperation(value = "查询成功订单列表---成功",notes = "前端必须传员工的id",httpMethod =
            "POST")
    public Result okOrderList(@RequestBody Map<String,Object> map){

        Integer staffId = (Integer) map.get("staffId");

        List<OrderBasicInformation> okOrderList;
        okOrderList = deliveryPortOrderService.okOrderList(staffId);
        try {
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        return Result.ok(okOrderList);
    }

    @PostMapping("/failedOrderList")
    @ApiOperation(value = "查询失败订单列表---失败",notes = "前端必须传员工的id",httpMethod =
            "POST")
    public Result failedOrderList(@RequestBody Map map){

        Integer staffId = (Integer) map.get("staffId");

        List<OrderBasicInformation> failedOrderList;

        try {
            failedOrderList = deliveryPortOrderService.failedOrderList("staffId");
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        return Result.ok(failedOrderList);
    }


    @PostMapping("/returnOrder")
    @ApiOperation(value = "退回订单",notes = "前端必须传订单的id,收货人id,收货人姓名",httpMethod =
            "POST")
    public Result returnOrder(@RequestBody Map map){
        String orderId = (String) map.get("orderId");
        Integer userId = (Integer) map.get("userId");
        String consigneeName = (String) map.get("consigneeName");

        Integer lines;
        try {
            lines = deliveryPortOrderService.returnOrder(orderId,userId,consigneeName);
        }catch (Exception e){
            return Result.failed("网络延迟,请稍等,数据已经保存");
        }
        return Result.ok(lines);
    }
}
